﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////


#pragma once
#include "GnufValueInput.h"
#include "GnufDropdownMenuControl.h"
#include "GnufCheckListControl.h"

namespace gnuf {

    class GNUF_BASE_EXPORT CheckListValueInputOption: public ICheckListControlAdaptationOption
    {
    public:

        enum CommitPolicy : std::uint8_t
        {
            eOneShot,                     // 下拉列表中点击后立刻提交
            eNonDropDownAreaButtonPress   // 自身区域以外点击提交
        };

        CheckListValueInputOption():
            SelectAllEnable(true),
            ListCommitPolicy(eNonDropDownAreaButtonPress)
        {}
        virtual ~CheckListValueInputOption() {}

        bool SelectAllEnable;
        std::wstring SelectAllCaption;
        std::vector<bool> EnableList;
        CommitPolicy ListCommitPolicy;
    };

    class GNUF_BASE_EXPORT CheckListValueInput
        : public ValueInput<std::vector<bool>>
        , public ICheckListControlHandler
    {
        DEFINE_CAST_DERIVED(gnuf::CheckListValueInput, gnuf::ValueInputBase)
    public:
        explicit CheckListValueInput(std::uint16_t, gcmp::OwnerPtr<Info>& ,std::vector< gcmp::OwnerPtr< Info > >&, std::vector<bool>, gcmp::OwnerPtr<CheckListValueInputOption>&);
        virtual ~CheckListValueInput();
        CheckListControl* listControl() { return m_listCtrl.get(); }

    protected:
        // Inherits from ValueInput...
        virtual void onPostValueChanged() override;
        virtual void onPostAbilityChanged() override;

        virtual void onCheckStatusChanged(const std::vector<bool>&) override;
        virtual const ICheckListControlAdaptationOption*
            onGetListControlAdaptationOption() const override { return m_option.get(); }
    private:
        gcmp::OwnerPtr< CheckListControl > m_listCtrl;
        gcmp::OwnerPtr< CheckListValueInputOption> m_option;
    };

}
